package com.ltg.framework.auth.api.holder;

import com.ltg.framework.auth.AuthInfo;
import org.springframework.core.NamedInheritableThreadLocal;

/**
 * @Version 1.0
 * @Author LTG
 * @ClassName CurrentUserHolder
 * @Date 2023/11/4 12:55
 */
public class CurrentUserHolder {

    private static final ThreadLocal<AuthInfo> currUserHolder = new NamedInheritableThreadLocal("Current User Thread Local");

    public static void resetCurrentUser() {
        currUserHolder.remove();
    }

    public static void setCurrentUser(AuthInfo currentUser) {
        currUserHolder.set(currentUser);
    }

    public static AuthInfo getCurrentUser(){
        return currUserHolder.get();
    }
}
